
package com.yunfei.api.v2.qiuzhi.webc;

import com.yunfei.api.v2.qiuzhi.contants.QiuZhiApiNotesContants;
import com.yunfei.api.v2.qiuzhi.contants.QiuZhiRequestMappingContants;
import com.yunfei.api.v2.qiuzhi.result.QiuZhiResult;
import com.yunfei.api.v2.qiuzhi.service.DianZanService;
import com.yunfei.api.v2.qiuzhi.service.QiuZhiCenterService;
import com.yunfei.api.v2.qiuzhi.service.QiuZhiHuiDaService;
import com.yunfei.api.v2.qiuzhi.service.QiuZhiTiWenService;
import com.yunfei.api.v2.user.contants.UserCenterContants;
import com.yunfei.api.v2.user.valid.*;
import com.yunfei.common.frontend.consts.CommonConsts;
import com.yunfei.common.json.result.ResultModel;
import com.yunfei.core.utils.enmu.ResultStatus;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
/**
 * @Description: 求知广场接口
 * @Author: zhengyunfei
 * @Date: 2018/6/15
 * @time:11:26
 */
@Api(value = "求知广场",tags = "求知广场")
@RestController
@RequestMapping("/api/v2/qiuzhi")
public class QiuZhiApiController {
    @Autowired
    private QiuZhiCenterService qiuZhiCenterService;
    @Autowired
    private QiuZhiTiWenService qiuZhiTiWenService;
    @Autowired
    private QiuZhiHuiDaService qiuZhiHuiDaService;
    @Autowired
    private DianZanService dianZanService;
    /**
    * @Description:最新1
    * @Author: zhengyunfei
    * @Date: 2018/10/30
    * @time:9:13
    */
      @PostMapping(CommonConsts.XIE_GANG+QiuZhiRequestMappingContants.ZUIXIN)
    @ApiOperation(value = QiuZhiApiNotesContants.ZUIXIN,notes = UserCenterContants.AUTHOR_NOTE,position = 1,response = QiuZhiResult.class)
    public ResultModel getZuiXin(@Valid QiuZhiValid requestParam, BindingResult bindingResult){
        ResultModel resultModel=new ResultModel();
        try{
            if (qiuZhiCenterService.zuixin(requestParam, bindingResult, resultModel)) return resultModel;
        }catch (Exception e){
            e.printStackTrace();
            resultModel.setCode(ResultStatus.ERROR.getCode());
            resultModel.setMessage(ResultStatus.ERROR.getMessage());
        }
        return resultModel;
    }
    /***推荐**/
    @PostMapping(CommonConsts.XIE_GANG+QiuZhiRequestMappingContants.TUIJIAN)
    @ApiOperation(value = QiuZhiApiNotesContants.TUIJIAN,notes = UserCenterContants.AUTHOR_NOTE,position = 1,response = QiuZhiResult.class)
    public ResultModel getTuiJian(@Valid QiuZhiValid requestParam, BindingResult bindingResult){
        ResultModel resultModel=new ResultModel();
        try{
            if (qiuZhiCenterService.tuijian(requestParam, bindingResult, resultModel)) return resultModel;
        }catch (Exception e){
            resultModel.setCode(ResultStatus.ERROR.getCode());
            resultModel.setMessage(ResultStatus.ERROR.getMessage());
        }
        return resultModel;
    }
    /***我的**/
    @PostMapping(CommonConsts.XIE_GANG+QiuZhiRequestMappingContants.WODE)
    @ApiOperation(value = QiuZhiApiNotesContants.WODE,notes = UserCenterContants.AUTHOR_NOTE,position = 1,response = QiuZhiResult.class)
    public ResultModel getWoDe(@Valid QiuZhiValid requestParam, BindingResult bindingResult,@Valid TokenForm tokenForm){
        ResultModel resultModel=new ResultModel();
        try{
            if (qiuZhiCenterService.wode(requestParam, bindingResult, tokenForm, resultModel)) return resultModel;
        }catch (Exception e){
            resultModel.setCode(ResultStatus.ERROR.getCode());
            resultModel.setMessage(ResultStatus.ERROR.getMessage());
        }
        return resultModel;
    }
    /***提问**/
    @PostMapping(CommonConsts.XIE_GANG+ QiuZhiRequestMappingContants.TIWEN)
    @ApiOperation(value = QiuZhiApiNotesContants.TIWEN,notes = UserCenterContants.AUTHOR_NOTE,position = 1,response = ResultModel.class)
    public ResultModel tiwen(TiWenValid requestParam, TokenForm tokenForm){
        ResultModel resultModel=new ResultModel();
        try{
            return qiuZhiTiWenService.tiwen(requestParam, tokenForm, resultModel);
        }catch (Exception e){
            e.printStackTrace();
            resultModel.setCode(ResultStatus.ERROR.getCode());
            resultModel.setMessage(ResultStatus.ERROR.getMessage());
        }
        return resultModel;
    }
    /***回答**/
    @PostMapping(CommonConsts.XIE_GANG+QiuZhiRequestMappingContants.HUIDA)
    @ApiOperation(value = QiuZhiApiNotesContants.HUIDA,notes = UserCenterContants.AUTHOR_NOTE,position = 1,response = ResultModel.class)
    public ResultModel huida(HuiDaValid requestParam, TokenForm tokenForm){
        ResultModel resultModel=new ResultModel();
        try{
            return qiuZhiHuiDaService.huida(requestParam, tokenForm, resultModel);
        }catch (Exception e){
            resultModel.setCode(ResultStatus.ERROR.getCode());
            resultModel.setMessage(ResultStatus.ERROR.getMessage());
        }
        return resultModel;
    }
    /***更多回答**/
    @PostMapping(CommonConsts.XIE_GANG+QiuZhiRequestMappingContants.MORE_HUIDA)
    @ApiOperation(value = QiuZhiApiNotesContants.MORE_HUIDA,notes = UserCenterContants.AUTHOR_NOTE,position = 1,response = ResultModel.class)
    public ResultModel moreHuida(HuiDaValid requestParam, TokenForm tokenForm){
        ResultModel resultModel=new ResultModel();
        try{
            return qiuZhiHuiDaService.moreHuida(requestParam, tokenForm, resultModel);
        }catch (Exception e){
            e.printStackTrace();
            resultModel.setCode(ResultStatus.ERROR.getCode());
            resultModel.setMessage(ResultStatus.ERROR.getMessage());
        }
        return resultModel;
    }
    /***回复**/
    @PostMapping(CommonConsts.XIE_GANG+QiuZhiRequestMappingContants.HUIFU)
    @ApiOperation(value = QiuZhiApiNotesContants.HUIFU,notes = UserCenterContants.AUTHOR_NOTE,position = 1,response = ResultModel.class)
    public ResultModel huifu(HuiFuValid requestParam, TokenForm tokenForm){
        ResultModel resultModel=new ResultModel();
        try{
            return qiuZhiHuiDaService.huifu(requestParam, tokenForm, resultModel);
        }catch (Exception e){
            resultModel.setCode(ResultStatus.ERROR.getCode());
            resultModel.setMessage(ResultStatus.ERROR.getMessage());
        }
        return resultModel;
    }
    //点赞
    @PostMapping(CommonConsts.XIE_GANG+QiuZhiRequestMappingContants.DIANZAN)
    @ApiOperation(value = QiuZhiApiNotesContants.DIANZAN,notes = UserCenterContants.AUTHOR_NOTE,position = 1,response = ResultModel.class)
    public ResultModel dianzan(DianZanValid requestParam, TokenForm tokenForm){
        ResultModel resultModel=new ResultModel();
        try{
            return dianZanService.dianzan(requestParam, tokenForm, resultModel);
        }catch (Exception e){
            resultModel.setCode(ResultStatus.ERROR.getCode());
            resultModel.setMessage(ResultStatus.ERROR.getMessage());
        }
        return resultModel;
    }

}
